package com.muyu.vehicle.controller;

import java.math.BigDecimal;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vehicle.common.log.annotation.Log;
import com.vehicle.common.log.enums.BusinessType;
import com.vehicle.common.security.annotation.PreAuthorize;
import com.muyu.vehicle.domain.VehicleDataInfo;
import com.muyu.vehicle.service.IVehicleDataInfoService;
import com.vehicle.common.core.web.controller.BaseController;
import com.vehicle.common.core.web.domain.AjaxResult;
import com.vehicle.common.core.utils.poi.ExcelUtil;
import com.vehicle.common.core.web.page.TableDataInfo;

/**
 * 车辆数据大屏Controller
 *
 * @author muyu
 * @date 2021-09-04
 */
@RestController
@RequestMapping("/data")
public class VehicleDataInfoController extends BaseController
{
    @Autowired
    private IVehicleDataInfoService vehicleDataInfoService;

    /**
     * 查询车辆数据大屏列表
     */
    @PreAuthorize(hasPermi = "vehicle:data:list")
    @GetMapping("/list")
    public TableDataInfo list(VehicleDataInfo vehicleDataInfo)
    {
        startPage();
        List<VehicleDataInfo> list = vehicleDataInfoService.selectVehicleDataInfoList(vehicleDataInfo);
        return getDataTable(list);
    }

    /**
     * 导出车辆数据大屏列表
     */
    @PreAuthorize(hasPermi = "vehicle:data:export")
    @Log(title = "车辆数据大屏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleDataInfo vehicleDataInfo) throws IOException
    {
        List<VehicleDataInfo> list = vehicleDataInfoService.selectVehicleDataInfoList(vehicleDataInfo);
        ExcelUtil<VehicleDataInfo> util = new ExcelUtil<VehicleDataInfo>(VehicleDataInfo.class);
        util.exportExcel(response, list, "车辆数据大屏数据");
    }

    /**
     * 获取车辆数据大屏详细信息
     */
    @PreAuthorize(hasPermi = "vehicle:data:query")
    @GetMapping(value = "/{sumMileage}")
    public AjaxResult getInfo(@PathVariable("sumMileage") BigDecimal sumMileage)
    {
        return AjaxResult.success(vehicleDataInfoService.selectVehicleDataInfoBySumMileage(sumMileage));
    }

    /**
     * 新增车辆数据大屏
     */
    @PreAuthorize(hasPermi = "vehicle:data:add")
    @Log(title = "车辆数据大屏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleDataInfo vehicleDataInfo)
    {
        return toAjax(vehicleDataInfoService.insertVehicleDataInfo(vehicleDataInfo));
    }

    /**
     * 修改车辆数据大屏
     */
    @PreAuthorize(hasPermi = "vehicle:data:edit")
    @Log(title = "车辆数据大屏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleDataInfo vehicleDataInfo)
    {
        return toAjax(vehicleDataInfoService.updateVehicleDataInfo(vehicleDataInfo));
    }

    /**
     * 删除车辆数据大屏
     */
    @PreAuthorize(hasPermi = "vehicle:data:remove")
    @Log(title = "车辆数据大屏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sumMileages}")
    public AjaxResult remove(@PathVariable BigDecimal[] sumMileages)
    {
        return toAjax(vehicleDataInfoService.deleteVehicleDataInfoBySumMileages(sumMileages));
    }
}
